<template>
  <div>
    <!--面包屑导航栏-->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>
        <router-link to="/home/orders">订单管理</router-link>
      </el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <!--输入框区域-->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="SendOrderList.query">
            <el-button slot="append" icon="el-icon-search" @click="SendSeek"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!--这里是表格区域-->
      <el-table
          :data="OrderData"
          border
          style="width: 100%"
          v-loading.fullscreen.lock="fullscreenLoading"
      >
        <el-table-column
            type="index"
            width="50"
            label="#"
        >
        </el-table-column>
        <el-table-column
            prop="order_number"
            label="订单编号"
        >
        </el-table-column>
        <el-table-column
            prop="order_price"
            label="订单价格"
        >
        </el-table-column>
        <el-table-column
            label="是否付款"
        >
          <template v-slot="scope">
            <el-tag :type="scope.row.order_pay==='0'?'danger':'success'">
              {{ scope.row.order_pay === '0' ? '未付款' : '已付款' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
            prop="is_send"
            label="是否发货"
        >
        </el-table-column>
        <el-table-column
            label="下单时间"
        >
          <template v-slot="scope">
            {{ scope.row.create_time| dateFormat }}
          </template>
        </el-table-column>
        <el-table-column
            label="操作"
        >
          <template v-slot="scope">
            <el-button type="primary" icon="el-icon-edit" @click="onEdit"></el-button>
            <el-button type="success" icon="el-icon-location" @click="showTime"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页器区域-->
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </el-card>
    <!--设置对话框区域-->
    <el-dialog
        title="提示"
        :visible.sync="SetDialogVisible"
        width="50%">
      <el-form :model="AddRuleForm" :rules="AddRules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader :options="cityData" v-model="AddRuleForm.address1"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="AddRuleForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="SetDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="SetDialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
    <!--显示物流进度对话框-->
    <el-dialog
        title="提示"
        :visible.sync="TimeDialogVisible"
        width="50%">
      <el-timeline>
        <el-timeline-item
            v-for="(activity, index) in WorkData"
            :key="index"
            :timestamp="activity.ftime">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
    <el-button @click="TimeDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="TimeDialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'

export default {
  name: "order",
  data() {
    return {
      //这里是发送给后台的参数信息
      SendOrderList: {
        pagenum: 1,
        pagesize: 10,
        //这是发送给后端的查询参数
        query: ''
      },
      OrderData: [],
      total: 0,
      //这个是控制加载图标是显示和隐藏
      fullscreenLoading: false,
      //控制设置对话框的显示和隐藏
      SetDialogVisible: false,
      //设置对话框里的表单的数据源
      AddRuleForm: {
        address1: [],
        address2: ''
      },
      //表单的验证规则
      AddRules: {
        address1: [
          {required: true, message: '请选择省市区', trigger: 'blur'},
        ],
        address2: [
          {required: true, message: '请输入详细地址', trigger: 'blur'},
        ]
      },
      //这是从别处导入的城市数据
      cityData: cityData,
      //控制展示物流进度的对话框的显示和隐藏
      TimeDialogVisible: false,
      //存储物流信息
      WorkData:[]


    }
  },
  methods: {
    async getOrderData() {
      this.fullscreenLoading = true;
      const {data: res} = await this.$http.get('orders', {params: this.SendOrderList});
      this.SendOrderList.query = '';
      if (res.meta.status !== 200) return this.$message.error('获取订单列表数据失败');
      this.OrderData = res.data.goods;
      this.total = res.data.total
      this.fullscreenLoading = false
      this.$message.success('获取订单列表数据成功')
      console.log(this.OrderData)
    },
    //页面显示数据条数发生变化时触发
    handleSizeChange(val) {
      this.SendOrderList.pagesize = val
      this.getOrderData();

    },
    //页数发生变化
    handleCurrentChange(val) {
      this.SendOrderList.pagenum = val
      this.getOrderData();
    },
    //发送查询请求的回调函数
    SendSeek() {
      this.getOrderData()
    },
    //点击设置按钮时触发的回调函数
    onEdit() {
      this.SetDialogVisible = true;
    },
    //点击展示物流进度的回调函数
    async showTime() {
      this.TimeDialogVisible=true;
      const {data: res} = await this.$http.get('kuaidi/1106975712662')
      if(res.meta.status!==200)return this.$message.error('获取物流信息失败')
      this.WorkData=res.data
      console.log(this.WorkData)
      this.$message.success('获取物流信息成功')

    }
  },
  created() {
    this.getOrderData();
  }
}
</script>

<style scoped>

</style>
